module dgl.graphics.ShaderProgram;

import tango.stdc.stringz;
import tango.io.Console;
import Integer = tango.text.convert.Integer;

import derelict.opengl.gl;

import dgl.Vector2;
import dgl.Vector3;
import dgl.Vector4;
import dgl.Matrix;

import dgl.graphics.FragmentShader;
import dgl.graphics.ShaderUniformCollection;
import dgl.graphics.VertexShader;
import dgl.graphics.Texture2D;

class ShaderProgram
{
	private GLuint m_id;
	
	private VertexShader m_vs;
	
	private FragmentShader m_fs;
	
	public ShaderUniformCollection uniforms;
	
	package GLuint id()
	{
		return m_id;
	}
	
	public VertexShader vertexShader()
	{
		return m_vs;
	}
	
	public FragmentShader fragmentShader()
	{
		return m_fs;
	}
	
	public this( VertexShader vs, FragmentShader fs )
	{
		m_vs = vs;
		m_fs = fs;
		this.buildShaders();
		uniforms = new ShaderUniformCollection( this );
	}
	
	private void buildShaders()
	{
		m_id = glCreateProgram();
		
		glAttachShader( m_id, m_vs.id );
		glAttachShader( m_id, m_fs.id );
		
		glLinkProgram( m_id );
	}
}